///////////////////////////////////////////////////////////
//  BaseGameLoop.as
//  Actionscript 3.0 implementation of Class BaseGameLoop
//  owner: http://www.imanit.com/
//  resource page: http://www.scuge.com/ 
//  For Game Architecture or Flash Team Management Consulting contact iman@imanit.com
//  This code is without warranty and is to be used at your own risk.
//  Created on:      06-Dec-2009 5:02:42 PM
//  Original author: iMAN
///////////////////////////////////////////////////////////

package org.gof.stream
{
	import com.iMANIT.OO.ThisIs;
	
	import flash.display.DisplayObjectContainer;
	
	import org.gof.display.IRenderer;
	import org.gof.state.BaseGameLogic;
	import org.gof.state.BaseGameState;
	import org.gof.stream.ITranslator;

	/**
	 * controlls all parts: GameLogic,
	 * TurnManager, Renderer, Translator, and Controller.
	 * @author iMAN
	 * @version 1.0
	 * @created 06-Dec-2009 5:02:42 PM
	 */
	public class BaseGameLoop
	{
		    /**
	     * whether the game engine is playing.
	     */
	    protected var _isPlaying: Boolean;
	        /**
	     * true when the app is stopped
	     */
	
	    protected var _isStopped: Boolean;
	    
	  
	    protected var renderer: IRenderer;
	    protected var gameState:BaseGameState;
	  
	    protected var stateManager:BaseGameLogic;
	    protected var translator: ITranslator;

		public function BaseGameLoop(myRenderer: IRenderer, myStateManager:BaseGameLogic, translator: ITranslator,gameState:BaseGameState): void
		{
			this.translator = translator; 
			this.gameState = gameState;		 	
	    	gameState.stateManagerRef =stateManager = myStateManager;
	    	this.translator.gameStateRef = gameState;
	    	renderer = myRenderer;
		}
		
		public function addGameObject(myGO:BaseGameObject, gameObjectMeta: IGOInputMeta = null): Object
		{
			
			gameState.addGameObject(myGO);
			renderer.addObject(myGO.name, translator.translate(myGO.position),myGO.displayData);
			return null;
		}

  
	
	   /**
	     * whether engine stream is playing
	     */
	  	public function get isPlaying() :Boolean
	  	{
	  		return(_isPlaying);	
	  	}
	    /**
	     * whether engine stream is stopped.
	     */
	  
	  	public function get isStopped(): Boolean
	  	{
	  		return(_isStopped);
	  	}
	  
	  	public function start(settings:ISettings = null): void
	  	{
			if (settings)
			{
				gameState.settings = settings;
			}
			_isPlaying =  true;
			_isStopped = false;
	  	}
	  
	  	public function stop(): void
	  	{
			_isPlaying =  false;
			_isStopped = true;	  		
	  	}
	  	
	  	public function removeAllObjects(): void
	  	{
			ThisIs.anAbstractFunction();	  		
	  	}
	  
	  	public function togglePausePlay(): void
	  	{
	  		ThisIs.anAbstractFunction();
	  	}
	  
	  	public function resume(settings:ISettings = null): void
	  	{
	  		ThisIs.anAbstractFunction();
	  	}
	  	
	  
		

	}//end BaseGameEngine

}